home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 8 code / AUX Hybrid Apps / AUX System Calls / src / getenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-09  |  927 b   |  51 lines  |  [TEXT/tefi]

  1. /*    @(#)getenv.c    2.1     */
  2. /*
  3.  *    auxgetenv(name)
  4.  *    returns ptr to value associated with name, if any, else NULL
  5.  */
  6. #define NULL    0
  7. static char *nvmatch();
  8.  
  9. pascal long     AUXDispatch(selector,q)
  10. short           selector;
  11. char            *q;
  12. extern        0xABf9;
  13. #define AUX_GET_ENVIRON 11              /* get pointer to environ */
  14.  
  15. char *
  16. auxgetenv(name)
  17. register char *name;
  18. {
  19.     register char *v;
  20.     char **p;
  21.     
  22.     /* copy the environment */
  23.     AUXDispatch(AUX_GET_ENVIRON,(char *)&p);
  24.  
  25.     if(p == NULL)
  26.         return(NULL);
  27.     while(*p != NULL)
  28.         if((v = nvmatch(name, *p++)) != NULL)
  29.             return(v);
  30.     return(NULL);
  31. }
  32.  
  33. /*
  34.  *    s1 is either name, or name=value
  35.  *    s2 is name=value
  36.  *    if names match, return value of s2, else NULL
  37.  *    used for environment searching: see getenv
  38.  */
  39.  
  40. static char *
  41. nvmatch(s1, s2)
  42. register char *s1, *s2;
  43. {
  44.     while(*s1 == *s2++)
  45.         if(*s1++ == '=')
  46.             return(s2);
  47.     if(*s1 == '\0' && *(s2-1) == '=')
  48.         return(s2);
  49.     return(NULL);
  50. }
  51.